const { loginHandler } = require("../../../utils/function.js");

require("../../../utils/util.js");

var t = getApp(), e = (require("../../../utils/function.js"), require("../../../data/mockData.js"), 
require("../../../api.js"));

wx.getStorageSync("openId");

Page({
    data: {
        logs: []
    },
    onLoad: function() {},
    fan: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    onShow: function() {
        var o = this;
        t.request({
            url: e.driver.getQrcode,
            method: "post",
            success: function(t) {
                0 == t.code && (wx.showToast({
                    title: t.msg,
                    icon: "none"
                }), setTimeout(function() {
                    wx.navigateBack({});
                }, 800)), o.setData({
                    authorize: t.data.img
                });
            }
        });
    },
    getUserInfo: function(o) {
        var n = this, s = wx.getStorageSync("scene") ? wx.getStorageSync("scene") : "";
        this.getSettings(), wx.showLoading({}), wx.login({
            success: function(o) {
                console.log(o);
                o.code && wx.getUserProfile({
                    success: function(i) {
                        console.log(i);
                        wx.hideLoading(), t.request({
                            url: e.user.login,
                            method: "post",
                            data: {
                                code: o.code,
                                iv: i.iv,
                                encryptedData: i.encryptedData,
                                id: s
                            },
                            success: function(e) {
                                console.log(e);
                                if (1 == e.code) {
                                    e.data.is_binding;
                                    t.showToast("登录成功", 1, 1e3, function() {
                                        wx.navigateBack({
                                            delta: 1
                                        });
                                    }), wx.setStorageSync("user_info", e.data), wx.setStorageSync("uid", e.data.id), 
                                    n.setData({
                                        authStatus: !0,
                                        is_GZH: !0
                                    }), wx.setStorageSync("access_token", e.data.access_token);
                                } else wx.removeStorage({
                                    key: "access_token"
                                }), wx.removeStorage({
                                    key: "uid"
                                }), wx.showToast({
                                    title: "登录失败",
                                    icon: "none",
                                    duration: 2e3
                                });
                            }
                        });
                    }
                });
            }
        });
    },
    getSettings: function() {
        wx.getSetting({
            success: function(t) {
                console.log(JSON.stringify(t), "初始化进入该页面"), void 0 != t.authSetting["scope.userLocation"] && 1 != t.authSetting["scope.userLocation"] ? wx.showModal({
                    title: "请求授权当前位置",
                    content: "需要获取您的地理位置，请确认授权",
                    success: function(t) {
                        t.cancel ? wx.showToast({
                            title: "拒绝授权",
                            icon: "none",
                            duration: 1e3
                        }) : t.confirm && wx.openSetting({
                            success: function(t) {
                                1 == t.authSetting["scope.userLocation"] ? (wx.showToast({
                                    title: "授权成功",
                                    icon: "success",
                                    duration: 1e3
                                }), wx.getLocation({
                                    success: function(t) {}
                                })) : wx.showToast({
                                    title: "授权失败",
                                    icon: "none",
                                    duration: 1e3
                                });
                            }
                        });
                    }
                }) : (t.authSetting["scope.userLocation"], wx.getLocation({
                    success: function(t) {}
                }));
            }
        });
    }
});